package org.person.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.person.springcloud.models.CommonResult;
import org.person.springcloud.models.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private int port;

    public static HashMap<Long, Payment> data = new HashMap<>();

    static {
        data.put(1l, new Payment(1l, "4283483204832048302840234"));
        data.put(2l, new Payment(2l, "4832904803284023840238443"));
        data.put(3l, new Payment(3l, "6788998493289423984923942"));
    }

    @GetMapping("/payment/{id}")
    public CommonResult<Payment> payment(@PathVariable("id") Long id) {
        Payment payment = data.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "from memory database, port" + port, payment);
        return result;
    }
}
